package net.ib.mtalk.ui.buddy.talk;

import net.ib.mtalk.R;
import net.ib.mtalk.database.DatabaseContract.BuddyTable;
import net.ib.mtalk.database.DatabaseContract.GroupTable;
import net.ib.mtalk.database.DatabaseContract.ParticipantsTable;
import net.ib.mtalk.database.DatabaseHelper.Buddy_Query;
import android.app.Activity;
import android.content.Context;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.LoaderManager;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.SimpleCursorTreeAdapter;
import android.widget.TextView;

public class BuddyTalkSimpleCursorTreeAdapter extends SimpleCursorTreeAdapter implements android.support.v4.widget.SimpleCursorAdapter.ViewBinder{

	private Context mContext;
	private LoaderManager manager;
	
	public BuddyTalkSimpleCursorTreeAdapter(Context context, Cursor cursor,
			int collapsedGroupLayout, int expandedGroupLayout,
			String[] groupFrom, int[] groupTo, int childLayout,
			int lastChildLayout, String[] childFrom, int[] childTo, LoaderManager loaderManager) {
		super(context, cursor, collapsedGroupLayout, expandedGroupLayout, groupFrom, groupTo, childLayout, lastChildLayout, childFrom, childTo);
		this.mContext = context;
		this.manager = loaderManager;
	}

	@Override
	protected Cursor getChildrenCursor(Cursor groupCursor) {
		Cursor cursor = null;
		int groupId = groupCursor.getInt(groupCursor.getColumnIndexOrThrow(GroupTable._ID));
		if(groupId != 1){
			Bundle args = new Bundle();
			args.putInt("id", groupId);
			
//			String selection = ParticipantsTable.KEY_PARTICIPANTS_GROUP + "=?";
//			String []selectionArgs = {String.valueOf(groupId)};
//			String sortOrder = BuddyTable.KEY_BUDDY_DISPLAYNAME;
//			cursor = mContext.getContentResolver().query(ParticipantsTable.buildBuddyGroupUri(), null, selection, selectionArgs, sortOrder);
//			manager.restartLoader(groupCursor.getPosition(), args, BuddyTalkListActivity1.BuddyTalkListFragment1.callback);
		}
			
		return null;
	}
	@Override
	public void setViewBinder(ViewBinder viewBinder) {
		// TODO Auto-generated method stub
		super.setViewBinder(viewBinder);
	}
	@Override
	public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
		if(view.getId() == R.id.buddy_child_check){
			
		} else if(view.getId() == R.id.buddy_child_profile){
			
		} else if(view.getId() == R.id.birthday_img){
			
		} else if(view.getId() == R.id.buddy_child_name){
			
		} else if(view.getId() == R.id.buddy_child_status_msg){
			
		} else if(view.getId() == R.id.buddy_relation_img){
			
//			setViewImage(view, value);
			return true;
		}
		// TODO Auto-generated method stub
		return false;
	}
	
	private static class ChildViewHolder {
		CheckBox checkBox;
		ImageView profile;
		ImageView birth_image;
		TextView name;
		TextView statusMsg;
		ImageView relation_image;
		RelativeLayout item;
		
		public ChildViewHolder(RelativeLayout item, boolean showcheckbox) {
			checkBox = (CheckBox)item.findViewById(R.id.buddy_child_check);
			profile = (ImageView)item.findViewById(R.id.buddy_child_profile);
			birth_image = (ImageView)item.findViewById(R.id.birthday_img);
			name = (TextView)item.findViewById(R.id.buddy_child_name);
			statusMsg = (TextView)item.findViewById(R.id.buddy_child_status_msg);
			relation_image = (ImageView)item.findViewById(R.id.buddy_relation_img);
			this.item = item;
			
			if(showcheckbox){
				checkBox.setVisibility(View.VISIBLE);
			} else{
				checkBox.setVisibility(View.GONE);
			}
		}
	}

}
